home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
stdio
/
RCS
/
setbuf.man,v
< prev
next >
Wrap
Text File
|
1989-01-04
|
4KB
|
220 lines
head 1.2;
branch ;
access ;
symbols ;
locks ; strict;
comment @@;
1.2
date 89.01.04.10.11.02; author ouster; state Exp;
branches ;
next 1.1;
1.1
date 89.01.04.09.54.53; author ouster; state Exp;
branches ;
next ;
desc
@@
1.2
log
@Added documentation for setvbuf.
@
text
@.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.\" @@(#)setbuf.3 6.3 (Berkeley) 10/16/87
.\"
.TH SETBUF 3S "October 16, 1987"
.UC 4
.SH NAME
setbuf, setbuffer, setlinebuf, setvbuf \- assign buffering to a stream
.SH SYNOPSIS
.B #include <stdio.h>
.PP
.B setbuf(stream, buf)
.br
.SM
.B FILE
.B *stream;
.br
.B char *buf;
.PP
.B setbuffer(stream, buf, size)
.br
.SM
.B FILE
.B *stream;
.br
.B char *buf;
.br
.B int size;
.PP
.B setlinebuf(stream)
.br
.SM
.B FILE
.B *stream;
.PP
\fBsetvbuf(stream, buf, mode, size)
.br
.SM
FILE
\fB*stream;
.br
\fBchar *buf;
.br
\fBint mode;
.br
\fBint size;\fR
.SH DESCRIPTION
The three types of buffering available are unbuffered, block buffered,
and line buffered.
When an output stream is unbuffered, information appears on the
destination file or terminal as soon as written;
when it is block buffered many characters are saved up and written as a block;
when it is line buffered characters are saved up until a newline is
encountered or input is read from stdin.
.I Fflush
(see
.IR fclose (3S))
may be used to force the block out early.
Normally all files are block buffered.
A buffer is obtained from
.IR malloc (3)
upon the first
.I getc
or
.IR putc (3S)
on the file.
If the standard stream
.B stdout
refers to a terminal it is line buffered.
The standard stream
.B stderr
is always unbuffered.
.PP
.I Setbuf
is used after a stream has been opened but before it is read or written.
The character array
.I buf
is used instead of an automatically allocated buffer. If
.I buf
is the constant pointer
.SM
.B NULL,
input/output will be completely unbuffered.
A manifest constant
.SM
.B BUFSIZ
tells how big an array is needed:
.IP
.B char
buf[BUFSIZ];
.PP
.IR Setbuffer ,
an alternate form of
.IR setbuf ,
is used after a stream has been opened but before it is read or written.
The character array
.I buf
whose size is determined by the
.I size
argument is used instead of an automatically allocated buffer. If
.I buf
is the constant pointer
.SM
.BR NULL ,
input/output will be completely unbuffered.
.PP
.I Setlinebuf
is used to change
.I stdout
or
.I stderr
from block buffered or unbuffered to line buffered.
Unlike
.I setbuf
and
.I setbuffer
it can be used at any time that the file descriptor is active.
.PP
\fISetvbuf\fR is the final form of \fIsetbuf\fR; as with \fIsetbuf\fR,
it must be invoked after a stream has been opened but before it is read
or written. The argument \fImode\fR determines how \fIstream\fR will
be buffered:
.SM
\fB_IOFBF\fR
causes input/output to be fully buffered,
.SM
\fB_IOLBF\fR
causes output to be line buffered, and
.SM
\fB_IONBF\fR
causes input/output to be unbuffered. The argument \fIsize\fR specifies how
large a buffer to use. If \fIbuf\fR is
.SM
\fBNULL\fR
, then \fIsetvbuf\fR
will allocate the buffer space; otherwise, it will use the space at
\fIbuf\fR (which must contain at least \fIsize\fR bytes). \fISetvbuf\fR
returns zero on success, or nonzero if an invalid value is given for
\fImode\fR or if the request cannot be honored.
.PP
A file can be changed from unbuffered or line buffered to block buffered
by using
.I freopen
(see
.IR fopen (3S)).
A file can be changed from block buffered or line buffered to unbuffered
by using
.I freopen
followed by
.I setbuf
with a buffer argument of
.SM
.BR NULL .
.SH "SEE ALSO"
fopen(3S),
getc(3S),
putc(3S),
malloc(3),
fclose(3S),
puts(3S),
printf(3S),
fread(3S)
.SH BUGS
The
.I setbuffer
and
.I setlinebuf
functions are not portable to non-4.2BSD versions of UNIX.
On 4.2BSD and 4.3BSD systems,
.I setbuf
always uses a suboptimal buffer size and should be avoided.
.I Setbuffer
is not usually needed
as the default file I/O buffer sizes are optimal.
@
1.1
log
@Initial revision
@
text
@d10 1
a10 1
setbuf, setbuffer, setlinebuf \- assign buffering to a stream
d37 13
d121 22
@